#include "NormalBlock.hpp"
#include "Game.hpp"


NormalBlock::NormalBlock(Game* g, unsigned int hp):
Block(g, true),
hitPoints(hp)
{
}

Vector3f GetColor(int hitPoints)
{
	switch(hitPoints)
	{
	case 5://yellow
		return Vector3f(1, 1, 0.5);
		break;
	case 4://blue
		return Vector3f(0.5, 0.5, 1);
		break;
	case 3://red
		return Vector3f(1, 0.5, 0.5);
		break;
	case 2://green
		return Vector3f(0.5, 1, 0.5);
		break;
	case 1://white
		return Vector3f(1, 1, 1);
		break;
	default://black
		return Vector3f(1.0f/hitPoints, 1.0f/hitPoints, 1.0f/hitPoints);
		break;
	}
}

void NormalBlock::onHit()
{
	game->AddParticleSystem(new SparksParticle(position+(cm.max-cm.min)/2, GetColor(hitPoints)));
	game->PlaySound("hit");
	hitPoints--;
	if(0==hitPoints)
	{
		manager->markToRemove(this);
		game->incrementScore(1);
	}
}

void NormalBlock::Render()
{
	//choose a color specific for the hp
	Vector3f col=GetColor(hitPoints);
	glColor3f(col.x, col.y, col.z);

	Block::Render();

	glColor3f(1, 1, 1);
}